;Z80 extension file
;This file extends the Z80 language to reduce the number of
;confusing idiosyncrasies (like "ex de,hl" but no "ex hl,de")
;as well as providing other useful subroutines.

;ex instructions with the params reversed, it is a simple exchange after all
#instruction "ex",2,"<1>11100011","R:8:4","L:(sp)"
#instruction "ex",1,"11100011","L:hl","L:(sp)"
#instruction "ex",1,"00001000","L:af'","L:af"
#instruction "ex",1,"11101011","L:hl","L:de"

;new ex instructions for the other register pairs (af, bc, de, ix, iy)
#macro "ex","R:reg1:2","R:reg2:2"
  #exec "push "+reg1
  #exec "push "+reg2
  #exec "pop "+reg1
  #exec "pop "+reg2
#endmacro
#macro "ex","R:reg1:4","R:reg2:4"
  #exec "push "+reg1
  #exec "push "+reg2
  #exec "pop "+reg1
  #exec "pop "+reg2
#endmacro
#macro "ex","R:reg1:2","R:reg2:4"
  #exec "push "+reg1
  #exec "push "+reg2
  #exec "pop "+reg1
  #exec "pop "+reg2
#endmacro
#macro "ex","R:reg1:4","R:reg2:2"
  #exec "push "+reg1
  #exec "push "+reg2
  #exec "pop "+reg1
  #exec "pop "+reg2
#endmacro